//初始化
mui.init();
var mask = mui.createMask(); //遮罩层
//获取本地储存数据
var my_phone = localStorage.getItem("my_phone");
var user_id = localStorage.getItem("user_id");
var is_realname, pay_password, description;
var status = 0; //修改手机号审核状态
//返回user页面
$(document).on('tap', '.go_user', function() {
	mui.openWindow({
		url: '../trading_area/business_detail.html',
		extras: {
			detailId: shopId
		},
		createNew: true,
	});
})
function formatTime (value){
  var d = new Date(value*1000);
  var year = d.getFullYear();
  var month = d.getMonth() + 1;
  var day = d.getDate();
  var hour = d.getHours();
  var minutes = d.getMinutes();
  var seconds = d.getSeconds();
	month < 10 ? (month = "0" + month) : month;
	day < 10 ? (day = "0" + day) : day;
	hour < 10 ? (hour = "0" + hour) : hour;
	minutes < 10 ? (minutes = "0" + minutes) : minutes;
	seconds < 10 ? (seconds = "0" + seconds) : seconds;
    return year+ '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds;
}

//userinfo接口调用
function userinfo() {
	mui.ajax(user_url + '/api/nearby_shop/consumeRecord', {
		data: {
			"page": 1,
			"size": 100,
			"shop_id": shopId,
		},
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		success: function(data) {
			console.log(JSON.stringify(data))
			if(data.code == 10000) {
				var html = ""
				var hotShop = data.resp.list;
				for(var i = 0; i < hotShop.length; i++) {
					var timeVal = hotShop[i].create_time;
					html += '<li class="mui-table-view-cell advance_record_li" onclick="detailPage('+hotShop[i].id+','+status+')">'
					html += '<a class="mui-pull-left">'
					html += ''+hotShop[i].text+''
					html += '<p>'+formatTime(timeVal)+'</p>'
					html += '</a>'
					html += '<span class="mui-pull-right" style="color:#e60012;">+<i>'+hotShop[i].number+'</i></span>'
//					html += '<span class="mui-icon mui-icon-forward account_icon"></span>'
					html += '</li>';
				}
				$(".advance_record_list").html(html);
			}
		},
		error: function(xhr, type, errorThrown) { //异常处理；
			console.log(type);
		}
	});
}
var shopId;
//页面进入执行方法
window.onload = function() {
	mui.plusReady(function() {
		var self = plus.webview.currentWebview();
		shopName = self.shopName;
		shopId = self.shopId;
		$('.mui-title').html(shopName);
		userinfo(); //用户接口方法
		plus.nativeUI.closeWaiting(); //关闭等待
		mask.close(); //关闭遮罩层
		// isPwd()
//		getSilverPrice()
			//页面刷新
		window.addEventListener('refresh_method', function(e) { //执行刷新
			location.reload();
		});
	});
}